package com.guofen.controller.sjq;

import com.guofen.pojo.SjqCompostProduceElectricity;
import com.guofen.pojo.SjqSolidliquidProduceElectricity;
import com.guofen.service.sjq.SjqSolidliquidProduceElectricityService;
import com.guofen.util.result.Result;
import com.guofen.util.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


@RequestMapping("/sjq/sjqSolidliquidProduceElectricity")
@Controller
@Api(tags = "SjqSolidliquidProduceElectricityController", description = "固液分离用电记录")
public class SjqSolidliquidProduceElectricityController {
    @Autowired
    private SjqSolidliquidProduceElectricityService sjqSolidliquidProduceElectricityService;

    //保存
    @ApiOperation("添加记录")
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ResponseBody
    public Result add(@ApiParam(name="reading",value="读数",required=true) @RequestParam String reading,
                               @ApiParam(name="reader",value="读表人",required=true) @RequestParam String reader,
                               @ApiParam(name="remarks",value="备注",required=true) @RequestParam String remarks){

        if (sjqSolidliquidProduceElectricityService.add(reading,reader,remarks))
            return ResultGenerator.genSuccessResult();
        else
            return ResultGenerator.genFailResult("保存失败");
    }



    @ApiOperation("获取 当日 最新 一条记录")
    @RequestMapping(value = "/getlast",method = RequestMethod.GET)
    @ResponseBody
    public Result get(){
        return  ResultGenerator.genSuccessResult(sjqSolidliquidProduceElectricityService.getlast());
    }


    @ApiOperation("删除记录")
    @RequestMapping(value = "/delete",method = RequestMethod.POST)
    @ResponseBody
    public Result delete(@ApiParam(name="id",value="ID",required=true) @RequestParam Integer id) {
        return ResultGenerator.genSuccessResult(sjqSolidliquidProduceElectricityService.delete(id));
    }

    @ApiOperation("修改记录")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public Result update(@ApiParam(name="id",value="id",required=true) @RequestParam(required = true) Integer id,
                         @ApiParam(name="date",value="date",required=false) @RequestParam(required = false) String date,
                         @ApiParam(name="reading_time",value="reading_time",required=false) @RequestParam(required = false) String reading_time,
                         @ApiParam(name="reading",value="reading",required=false) @RequestParam(required = false) Double reading,
                         @ApiParam(name="reader",value="reader",required=false) @RequestParam(required = false) String reader,
                         @ApiParam(name="remarks",value="remarks",required=false) @RequestParam(required = false) String remarks
    ) {
        SjqSolidliquidProduceElectricity record = new SjqSolidliquidProduceElectricity();
        record.setId(id);
        record.setDate(date);
        record.setReadingTime(reading_time);
        record.setReading(reading);
        record.setReader(reader);
        record.setRemarks(remarks);

        return ResultGenerator.genSuccessResult(sjqSolidliquidProduceElectricityService.update(record));
    }

    @ApiOperation("查找记录")
    @RequestMapping(value = "/select",method = RequestMethod.POST)
    @ResponseBody
    public Result select(@ApiParam(name="pageSize",value="页容量",required=true) @RequestParam Integer pageSize,
                         @ApiParam(name="currentPage",value="当前页",required=true) @RequestParam Integer currentPage,
                         @ApiParam(name="startTime",value="开始时间(时间戳：毫秒)",required = false) @RequestParam(required = false) Long startTime,
                         @ApiParam(name="endTime",value="截止时间(时间戳：毫秒)", required = false) @RequestParam(required = false) Long endTime) {
        if (startTime == null || endTime == null)
            return ResultGenerator.genSuccessResult(sjqSolidliquidProduceElectricityService.get(pageSize, currentPage));
        else
            return ResultGenerator.genSuccessResult(sjqSolidliquidProduceElectricityService.getByTime(pageSize, currentPage, startTime, endTime));
    }

}
